package com.xqledu.admin.entry.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.xqledu.admin.entry.enumeration.StatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
 * @description: 返回类封装
 * @author: 向其林
 * @date: 2023/5/6 0006 22:42
 * @version: 1.0
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)//去除null结果
public class Result<T> {

    private Integer code;

    private String message;

    private T date;

    public static Result success(){
        return new Result(StatusEnum.SUCCESS.getCode(), StatusEnum.SUCCESS.getMessage(), null);
    }

    public Result success(T date){
        return new Result(StatusEnum.SUCCESS.getCode(), StatusEnum.SUCCESS.getMessage(), date);
    }

    public static Result error(StatusEnum statusEnum){
        return new Result(statusEnum.getCode(), statusEnum.getMessage(), null);
    }

    public Result error(StatusEnum statusEnum, T date){
        return new Result(statusEnum.getCode(), statusEnum.getMessage(), date);
    }
}
